load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@aspect_rules_js//js:defs.bzl", "js_test")
load("//integration/ts-compat:import-all-entry-points.bzl", "generate_import_all_entry_points_file")

package(default_visibility = ["//visibility:public"])

write_file(
    name = "import-all-entry-points-file",
    out = "import-all-entry-points.ts",
    content = [generate_import_all_entry_points_file()],
)

# List of TypeScript packages that we want to run the compatibility test against.
# The list contains NPM module names that resolve to the desired TypeScript version.
typescript_version_packages = [
    "typescript",
]

# Generates a NodeJS test for each configured TypeScript version.
[
    js_test(
        name = ts_pkg_name,
        args = [ts_pkg_name],
        chdir = package_name(),
        data = [
            "helpers.mjs",
            "test.mjs",
            ":import-all-entry-points-file",
            "//:node_modules/shelljs",
            "//integration:node_modules/@angular/cdk",
            "//integration:node_modules/@angular/cdk-experimental",
            "//integration:node_modules/@angular/google-maps",
            "//integration:node_modules/@angular/material",
            "//integration:node_modules/@angular/material-experimental",
            "//integration:node_modules/@angular/youtube-player",
            "//:node_modules/%s" % ts_pkg_name,
            "//:node_modules/@types/node",
            "//:node_modules/@types/selenium-webdriver",
        ],
        entry_point = "test.mjs",
    )
    for ts_pkg_name in typescript_version_packages
]
